<template>
  <div class="w-full">
    <el-breadcrumb class="flex items-center h-full" separator-icon="ArrowRight">
      <transition-group name="breadcrumb" enter-active-class="animate__animated animate__fadeInRight">
        <el-breadcrumb-item v-for="(item, index) in breadcrumbList" :key="item.path">
          <div class="flex-center">
            <EcoIcon class="mr-1" v-if="breadcrumbIcon && item.meta.icon" :icon="iconClass(item.meta)" />
            <span v-if="item.redirect === 'noredirect' || index === breadcrumbList.length - 1" class="color-gray-400">
              {{ item.meta.title }}
            </span>
            <a v-else>
              {{ item.meta.title }}
            </a>
          </div>
        </el-breadcrumb-item>
      </transition-group>
    </el-breadcrumb>
  </div>
</template>
<script setup lang="ts">
import { RouteLocationMatched } from 'vue-router'
import { useSettingStore } from '@/stores'
const settingStore = useSettingStore()
const { breadcrumbIcon } = storeToRefs(settingStore)
const currentRoute = useRoute()
const breadcrumbList = ref<Array<RouteLocationMatched>>([])
const getBreadcrumb = () => {
  const matched = currentRoute.matched.filter(item => item.meta && item.meta.title)
  breadcrumbList.value = matched.filter(item => {
    return item.meta && item.meta.title && item.meta.breadcrumb !== false
  })
}
const iconClass = (mate: any) => {
  return mate.icon as string
}
watchEffect(() => {
  if (currentRoute.path.startsWith('/redirect/')) {
    return
  }
  getBreadcrumb()
})
</script>
